/**
 * 佣金管理
 */
define(function (require, exports, module) {
    var $ = require("jquery");
    var angular = require("angular");
    require("angular-route");
    require("angular-ui");
    require("angular-interceptor");
    require("pagination");
    require("authorize");
    require("permission");
    var util = require("util");
    var _ = require("underscore");
    // require("./common");
    var Template = require("/public/js/lib/template");

    var app = angular.module('app', ['ngRoute', 'ngUI', 'ngInterceptor']);

    function queryService($http, $q) {
        var service = {
            pageIndex:1,
            pageSize:10,
            hasData:false,
            // 项目列表
            projectList: [],
            queryDetail:function(pageIndex){
                // 初始化数据
                var promises = [
                    // 项目列表
                    $http.get('/api/index.php?r=qmyx/city-regional/get-data-for-project-list&pageSize='+this.pageSize+'&pageIndex='+pageIndex)
                ];

                return $q.all(promises).then(function (xhrs) {
                    var i = 0;
                    service.projectList = xhrs[i++].data.data;
                    service.total = service.projectList.rowCount;
                    service.hasData = true;
                    service.loaded = true;
                });
            },
            initData: function() {
                this.queryDetail(1);
            },
        };
        return service;
    };

    app.factory('query', ['$http', '$q', queryService]);

    function StatisticsController($scope,query) {
        $scope.query = query;

        setTimeout(function () {
            // setTimeout 为了让路由先完成，防止 dom 元素闪动
            $scope.$apply(function() {
                query.initData();
            });
        }, 0);
    }
    app.controller('StatisticsController', ['$scope', 'query',StatisticsController]);

    angular.bootstrap(document.getElementById('ng-app'), ['app']);
});